# _*_ coding: utf-8 _*_
from odoo import models, fields, api
from odoo.exceptions import AccessDenied
from odoo.osv.expression import OR


class ResUsers(models.Model):
    _inherit = "res.users"
    #
    # wecom_userid = fields.Char()
    #
    # @api.model
    # def _get_login_domain(self, login):
    #     domain = super(ResUsers, self)._get_login_domain(login)
    #     domain = OR([domain, [('wecom_userid', '=', login)]])
    #     return domain

    def _check_credentials(self, password, env):
        # password is userid
        try:
            return super(ResUsers, self)._check_credentials(password, env)
        except AccessDenied:
            if not (password.startswith('fkc_sso->') and self.sudo().search_count([
                ("id", "=", self.env.uid),
                ("login", "=", password[9:]),
            ]) > 0):
                raise
